﻿
/*****
 * 每一个页面都可能需要获取到AppId、AppKey、WorkId、MPUserId、SSOUserId、ssotoken这几个关键变量
 * AppId、AppKey：这两个是根据页面来的，每个页面不管登录哪个用户，都是固定的
 * 
 * WorkId、MPUserId、SSOUserId、ssotoken：这几个是根据登录用户来获取的
 * 
 */

var lobstercommon = {
    name: "lobsterh5",
    needlogin: true,//需要登录，不能匿名
    //获取url中的参数
    GetUrlParam: function (name, url) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        if (url) {
            var r = url.substr(url.indexOf('?') + 1).match(reg);
            if (r != null)
                return unescape(r[2]);
        }
        else {
            var r = window.location.search.substr(1).match(reg); //匹配目标参数
            if (r != null)
                return unescape(r[2]);
        }
        return null; //返回参数值
    },
    //获取AppId
    //不能用本地缓存，每一个页面可能属于不同应用
    GetAppId: function () {
        var self = lobstercommon;
        var appid = self.GetUrlParam('appid') || -1;
        if (appid != -1) {
            return appid;
        }

        if (location.pathname.indexOf('/webapp/') > -1 || location.pathname.indexOf('/weuiapp/') > -1) {
            // /webapp/3025/bookmanage.html
            // /weuiapp/3025/index.html
            var arr = location.pathname.split('/');
            if (arr.length >= 3) {
                appid = arr[2];//取出3025
            }
        }
        else {
            var appid = self.GetUrlParam('appid') || -1;
        }

        return appid || -1;
    },
    GetAppKey: function () {
        var self = lobstercommon;
        var appid = self.GetAppId();
        if (appid > 0) {
            var res = self.RequestData('/basic/v1/basicdata/getappkey', 'GET', { appid: appid }, false);
            return res.data.appkey;
        } else {
            return "";
        }
    },
    //获取ssotoken
    GetSSOToken: function () {
        var ssotoken;

        if (lobstercommon.name == "lobsterh5") {
            ssotoken = localStorage.getItem('customer_sso_token');
        }
        else if (lobstercommon.name == "lobsterlayui") {
            ssotoken = localStorage.getItem('sso_token');
        }
        else if (lobstercommon.name == "lobsteramis") {
            ssotoken = localStorage.getItem('sso_token') || localStorage.getItem('customer_sso_token');
        }

        return ssotoken || "";
    },
    //获取WorkId
    GetWorkId: function () {
        var self = lobstercommon;

        var WorkId = -1;
        var login;

        if (lobstercommon.name == "lobsterlayui") {
            login = localStorage.getItem("logindata");
        } else if (lobstercommon.name == "lobsterh5") {
            login = localStorage.getItem("customer_logindata");
        }
        else if (lobstercommon.name == "lobsteramis") {
            login = localStorage.getItem('logindata') || localStorage.getItem('customer_logindata');
        }
        if (login) {
            var loginobj = JSON.parse(login);
            WorkId = loginobj.WorkId;
            //缓存WorkId
            localStorage.setItem("WorkId", WorkId);
        } else {
            WorkId = self.GetUrlParam('WorkId') || -1;//从url参数获取
            if (WorkId == -1) {
                WorkId = localStorage.getItem("WorkId") || -1;
            } else {
                //缓存WorkId
                localStorage.setItem("WorkId", WorkId);
            }
        }

        return WorkId || -1;
    },
    //获取MPUserId
    GetMPUserId: function () {
        var login;

        if (lobstercommon.name == "lobsterlayui") {
            login = localStorage.getItem("logindata");
        } else if (lobstercommon.name == "lobsterh5") {
            login = localStorage.getItem("customer_logindata");
        }
        else if (lobstercommon.name == "lobsteramis") {
            login = localStorage.getItem('logindata') || localStorage.getItem('customer_logindata');
        }
        if (login) {
            var loginobj = JSON.parse(login);
            return loginobj.UserId;
        }
        return -1;
    },
    //获取SSOUserId
    GetSSOUserId: function () {
        var login;

        if (lobstercommon.name == "lobsterlayui") {
            login = localStorage.getItem("logindata");
        } else if (lobstercommon.name == "lobsterh5") {
            login = localStorage.getItem("customer_logindata");
        }
        else if (lobstercommon.name == "lobsteramis") {
            login = localStorage.getItem('logindata') || localStorage.getItem('customer_logindata');
        }
        if (login) {
            var loginobj = JSON.parse(login);
            return loginobj.SSOUserId;
        }
        return -1;
    },
    //获取登录数据
    GetLoginData: function (callback, failback) {
        var login;

        if (lobstercommon.name == "lobsterlayui") {
            login = localStorage.getItem("logindata");
        } else if (lobstercommon.name == "lobsterh5") {
            login = localStorage.getItem("customer_logindata");
        }
        else if (lobstercommon.name == "lobsteramis") {
            login = localStorage.getItem('logindata') || localStorage.getItem('customer_logindata');
        }
        if (login) {
            var loginobj = JSON.parse(login);
            if (callback) {
                callback(loginobj);
            }
            return loginobj;
        } else {
            if (failback) {
                failback();
            }
            return null;
        }
    },
    //获取header数据
    GetHeaderData: function (content_type) {
        var self = lobstercommon;
        //规划header传递数据
        //1.Authorization
        //2.lobster-workid
        //3.lobster-appid
        //4.lobster-ssotoken
        //5.lobster-mpuserid
        //6.lobster-ssouserid
        var header = {};
        if (content_type != '') {
            header['content-type'] = (content_type || 'application/json');
        }
        var ssotoken = self.GetSSOToken();
        if (ssotoken) {
            header.Authorization = "Bearer " + ssotoken;
            header["lobster-ssotoken"] = ssotoken;
        }
        header["lobster-workid"] = self.GetWorkId();
        header["lobster-appid"] = self.GetAppId();
        header["lobster-mpuserid"] = self.GetMPUserId();
        header["lobster-ssouserid"] = self.GetSSOUserId();

        return header;
    },
    //获取LowCodeUrl
    GetLowCodeUrl: function (funname, debug = false) {
        var url = "/lowcode/?fun=" + funname;
        if (lobstercommon.name == "lobsterlayui") {
            //默认加参数view=layui
            url += "&view=layui";
        }
        else if (lobstercommon.name == "lobsterh5") {
            //默认加参数view=weui
            url += "&view=weui";
        }

        if (debug === true) {
            url += "&debug=true";
        }

        return url;
    },
    //Web请求api
    RequestData: function (url, method, data, _async = true) {

        var self = lobstercommon;
        var vdata;
        var ssotoken;
        if (method == "POST") {
            vdata = data ? JSON.stringify(data) : "";
        }
        else {
            vdata = data;
        }
        //规划header传递数据
        //1.Authorization
        //2.lobster-workid
        //3.lobster-appid
        //4.lobster-ssotoken
        //5.lobster-mpuserid
        //6.lobster-ssouserid
        var header = self.GetHeaderData();

        if (_async == true) {
            return new Promise((resolve, reject) => {

                $.ajax({
                    type: method,
                    url: url,
                    data: vdata,
                    dataType: 'json',
                    headers: header,
                    async: true,
                    timeout: 10000,
                    success: function (res) {
                        try {
                            var retobj = res;
                            if (retobj.code == 0) {
                                resolve(retobj.data);
                            }
                            else if (retobj.code == 1) {
                                reject(retobj);//返回错误
                            }
                            else {
                                resolve(retobj); //不是code\msg\data结构，返回成功
                            }
                        }
                        catch (e) {
                            resolve(res);//不是Json结构,返回原始数据
                        }
                    },
                    error: function (xhr) {

                        //认证失败返回登录页
                        if (xhr.status == 401 || xhr.status == 403) {
                            if (lobstercommon.name == "lobsterlayui") {
                                location.href = "/admin/login/index.html";
                            }
                            else if (lobstercommon.name == "lobsterh5") {
                                location.href = "/customer/login.html";
                            }
                        }

                        reject({
                            code: xhr.status,
                            msg: xhr
                        })
                    },
                });
            })
        }
        else {
            var retdata;
            $.ajax({
                type: method,
                url: url,
                data: vdata,
                dataType: 'json',
                headers: header,
                async: false,
                timeout: 10000,
                success: function (res) {
                    try {
                        var retobj = res;
                        retdata = retobj;
                    }
                    catch (e) {
                        // resolve(res);//不是Json结构,返回原始数据
                        retdata = res;
                    }
                },
                error: function (xhr) {
                    //认证失败返回登录页
                    if (xhr.status == 401 || xhr.status == 403) {
                        if (lobstercommon.name == "lobsterlayui") {
                            location.href = "/admin/login/index.html";
                        }
                        else if (lobstercommon.name == "lobsterh5") {
                            location.href = "/customer/login.html";
                        }
                    }
                    retdata = { code: xhr.status, msg: xhr };
                },
            });

            return retdata;
        }
    },
    GET: function (url, data) {
        return lobstercommon.RequestData(url, 'GET', data);
    },
    POST: function (url, data) {
        return lobstercommon.RequestData(url, 'POST', data);
    },
    //通过函数名调用云API
    GETAPI: function (funname, data, debug = false) {
        var url = lobstercommon.GetLowCodeUrl(funname, debug);
        return lobstercommon.RequestData(url, 'GET', data);
    },
    //通过函数名调用云API
    POSTAPI: function (funname, data, debug = false) {
        var url = lobstercommon.GetLowCodeUrl(funname, debug);
        return lobstercommon.RequestData(url, 'POST', data)
    },
    //上传文件到OSS
    OSSUploadFile: function (elemid, progress, success, fail) {
        var self = lobstercommon;
        var config = JSON.parse(localStorage.getItem("OSSConfig"));
        $('body').on('change', elemid, function () {
            var file = $(elemid).get(0).files[0];
            if (!file) return;

            var fileUpload = async function (file, func, suc, fail) {
                const client = new OSS({
                    // yourRegion填写Bucket所在地域。以华东1（杭州）为例，Region填写为oss-cn-hangzhou。
                    region: config.EndPoint.split('.')[0],// 'oss-cn-shenzhen',
                    // 从STS服务获取的临时访问密钥（AccessKey ID和AccessKey Secret）。
                    accessKeyId: config.AccessKeyId,// 'LTAI4GJQuzgwdRdDnJyUd6XG',
                    accessKeySecret: config.AccessKeySecret, //'xT1jd0f37JXQJa4z3nthnqebzvq4Om',
                    // 从STS服务获取的安全令牌（SecurityToken）。
                    stsToken: '',
                    // 填写Bucket名称。
                    bucket: config.BucketName//'uxmall'
                });
                const file_name = 'files/' + file.name;
                // 开始分片上传。
                //this.multipartUpload(file_name,file);
                try {
                    // 填写Object完整路径。Object完整路径中不能包含Bucket名称。
                    // 您可以通过自定义文件名（例如exampleobject.txt）或目录（例如exampledir/exampleobject.txt）的形式，实现将文件上传到当前Bucket或Bucket中的指定目录。
                    const result = await client.put(file_name, file, {

                        progress: function (p, checkpoint) {
                            // 断点记录点。浏览器重启后无法直接继续上传，您需要手动触发上传操作。
                            //tempCheckpoint = checkpoint;
                            func && func(p);
                        },
                        meta: { year: 2021, people: 'dev' },
                        mime: file.type
                    })
                    result.url = config.CustomDomain + '/' + result.name;

                    var _data = { appId: self.GetAppId(), filename: file.name, filelength: file.size, filetype: 1, fileurl: result.url };
                    //保存fileurl到数据库
                    self.GET('/basic/v1/OSS/SaveOSSFile', _data);

                    suc && suc(result);

                } catch (e) {
                    fail && fail(e);
                }
            }

            if (config) {
                fileUpload(file, progress, success, fail);
            } else {
                self.GET('/basic/v1/OSS/GetOSSConfig').then(data => {
                    config = data.oss;
                    localStorage.setItem("OSSConfig", JSON.stringify(config));
                    fileUpload(file, progress, success, fail);
                });
            }


        });
    },
    //调用外部应用的服务
    CALLOUTSERVICE: function (servicename, data) {
        return lobstercommon.POST("/basic/v1/OutService/ExecService", { servicename: servicename, appid: lobstercommon.GetAppId(), data: JSON.stringify(data) });
    },
    //获取系统参数
    GetSystemConfigs: function (workid, appid, paraids) {
        return lobstercommon.GET("/basic/v1/basicdata/GetSystemConfigs", { workid: workid, appid: appid, paraids: paraids });
    },
    SendSMS: function (workid, appid, phone, smstemplateid, parameters) {
        return lobstercommon.POST('/basic/v1/basicdata/SendSMS', { workid: workid, appid: appid, phone: phone, smstemplateid: smstemplateid, parameters: parameters });
    },
    GetBaseDict: function (classid) {
        return lobstercommon.GET("/basic/v1/basicdata/GetBaseDict", { classid: classid });
    },
    GetAppBaseDict: function (appid, classid) {
        return lobstercommon.GET("/basic/v1/basicdata/GetAppBaseDict", { appid: appid, classid: classid });
    },
    //0免费版 1专业版
    GetPowerType: function () {
        var self = lobstercommon;
        var res = self.RequestData('/basic/v1/basicdata/GetPowerType', 'GET', { ssouserid: self.GetSSOUserId() }, false);
        return res.data.type;
    },
}

var ImportWord = {
    data: {
        appid: -1,
        workid: -1,
        displayResult: null
    },
    init: function (elem, appid, workid, callbackdisplayResult) {
        var self = this;
        self.data.appid = appid;
        self.data.workid = workid;
        self.data.displayResult = callbackdisplayResult;
        document.getElementById(elem).addEventListener("change", (event) => {
            self.readFileInputEventAsArrayBuffer(event, function (arrayBuffer) {
                var options = {
                    convertImage: mammoth.images.imgElement(function (image) {
                        return image.read("base64").then(function (imageBuffer) {

                            //上传图片
                            return {
                                //src: "data:" + image.contentType + ";base64," + imageBuffer
                                //src:"https://oss.uxhealthy.com/20210830/af550eb4-ac00-4f14-b904-3068d292b5a4.png"
                                src: self.uploadimage(image.altText, imageBuffer)
                            };
                        });
                    })
                };

                mammoth.convertToHtml({ arrayBuffer: arrayBuffer }, options)
                    .then(self.data.displayResult)
                    .done();
            });
        }, false);
    },
    readFileInputEventAsArrayBuffer: function (event, callback) {
        var file = event.target.files[0];

        var reader = new FileReader();

        reader.onload = function (loadEvent) {
            var arrayBuffer = loadEvent.target.result;
            callback(arrayBuffer);
        };

        reader.readAsArrayBuffer(file);
    },
    uploadimage: function (filename, imageBuffer) {
        filename = filename || "default.png";
        var self = this;
        var returl = "default.png";
        $.ajax({
            type: 'post',
            async: false,//必须改为同步
            url: '/basic/v1/OSS/UploadBase64?workid=' + self.data.workid + '&appid=' + self.data.appid + '&fileType=1&filename=' + filename,
            headers: {
                'Content-Type': 'text/plain; charset=utf-8'
            },
            data: imageBuffer,
            success: function (res) {
                res = JSON.parse(res);
                if (res.data.url) {
                    returl = res.data.url;
                }
            },
            error: function () {

            }
        });

        return returl;
    }
};

//weuiapp开发
var lobsterh5 = {
    data: {
        PageStateData: []
    },
    main: function (page, needlogin = true) {
        $(function () {
            lobstercommon.name = "lobsterh5";
            lobstercommon.needlogin = needlogin;
            lobstercommon.GetWorkId();
            if (needlogin) {//需要进行登录才能执行
                lobstercommon.GetLoginData((right) => {
                    //验证登录
                    page.pageload(right);
                }, () => {
                    var pathname = window.location.pathname;
                    location.href = "/customer/login.html?callback=" + encodeURI(pathname);
                })
            } else {//无需登录
                page.pageload();
            }
        });
    },
    GetAppId: lobstercommon.GetAppId,
    GetAppKey: lobstercommon.GetAppKey,
    GetSSOToken: lobstercommon.GetSSOToken,
    GetWorkId: lobstercommon.GetWorkId,
    GetMPUserId: lobstercommon.GetMPUserId,
    GetSystemConfigs: lobstercommon.GetSystemConfigs,
    SendSMS: lobstercommon.SendSMS,
    GetBaseDict: lobstercommon.GetBaseDict,
    GetAppBaseDict: lobstercommon.GetAppBaseDict,
    GetUrlParam: lobstercommon.GetUrlParam,//获取url中的参数
    GetHeaderData: lobstercommon.GetHeaderData,
    GetLowCodeUrl: lobstercommon.GetLowCodeUrl,
    GET: lobstercommon.GET,
    POST: lobstercommon.POST,
    GETAPI: lobstercommon.GETAPI,
    POSTAPI: lobstercommon.POSTAPI,
    CALLOUTSERVICE: lobstercommon.CALLOUTSERVICE,
    OSSUploadFile: lobstercommon.OSSUploadFile,
    GetLoginData: lobstercommon.GetLoginData,
    //判断是否登录
    hasLogin: function () {
        var _hasLogin = JSON.parse(localStorage.getItem("customer_hasLogin")) || false;
        if (_hasLogin) {
            //还需要验证token是否失效
            lobstercommon.GetLoginData((right) => {
                //比较当前时间是否大于token失效时间
                var nowdate = new Date();
                var expirestime = new Date(right.ExpiresTime);

                if (nowdate.getTime() > expirestime.getTime()) {
                    _hasLogin = false;
                }
            });
        }
        return _hasLogin;
    },
    //成功登录
    SucceedLogin: function (data) {
        if (data) {
            localStorage.setItem('customer_hasLogin', true);
            localStorage.setItem("customer_sso_token", data.sso_token);
            localStorage.setItem("customer_logindata", JSON.stringify(data.logindata));
            localStorage.setItem('customer_openId', data.openId);
        }
    },
    //退出登录
    ExitLogin: function () {
        var self = this;
        if (self.hasLogin()) {
            localStorage.clear();
            location.href = "/customer/login.html";
        }
    },
    //获取用户信息
    GetMPUserInfo: function (backdata) {
        var self = this;

        self.GET("/admin/v1/CHome/GetMPUser").then(res => {
            var userinfo = res.user;
            if (backdata) {
                backdata(userinfo);
            }
        })
    },
    //表单处理
    WeUISetForm: function (elem, val) {
        if (val) {
            var form = $(elem);
            $.each(val, function (key, value) {
                var formitem = form.find('input[name="' + key + '"]');
                if (formitem.length > 0) {
                    if ($(formitem[0]).attr('weui-type') == "select") {
                        var items = $(formitem[0]).data("weui-select").config.items;
                        $(formitem[0]).attr("data-values", value);
                        $.each(items, function (index, item) {
                            if (item.value == value) {
                                $(formitem[0]).val(item.title);
                            }
                        })
                    } else {
                        $(formitem[0]).val(value);
                    }
                }
            })
        }
    },
    WeUIGetForm: function (elem, val) {
        var formval = {};
        var form = $(elem);
        if (val) {
            formval = val;
            $.each(formval, function (key, value) {
                var formitem = form.find('input[name="' + key + '"]');
                if (formitem.length > 0) {
                    if ($(formitem[0]).attr('weui-type') == "select") {
                        formval[key] = $(formitem[0]).attr("data-values");
                    } else {
                        formval[key] = $(formitem[0]).val();
                    }
                }
            });

        } else {
            var formitem = form.find('input[name]');
            $.each(formitem, function (index, item) {
                var name = $(item).attr('name');
                if (name) {
                    if ($(item).attr('weui-type') == "select") {
                        formval[name] = $(item).attr("data-values");
                    }
                    else {
                        formval[name] = $(item).val();
                    }
                }
            });
        }
        return formval;
    },
    //设置页面级缓存
    SetPageStorage: function (key, val) {
        localStorage.setItem("page_" + location.pathname + "_" + key, val);
    },
    //设置应用级缓存
    SetAppStorage: function (key, val) {
        localStorage.setItem("app_" + this.GetAppId() + "_" + key, val);
    },
    //设置全局级缓存
    SetGlobalStorage: function (key, val) {
        localStorage.setItem("global_" + key, val);
    },
    //获取页面级缓存
    GetPageStorage: function (key) {
        return localStorage.getItem("page_" + location.pathname + "_" + key);
    },
    //获取应用级缓存
    GetAppStorage: function (key) {
        return localStorage.getItem("app_" + this.GetAppId() + "_" + key);
    },
    //获取全局级缓存
    GetGlobalStorage: function (key) {
        return localStorage.getItem("global_" + key);
    },
    //增加页面中组件状态缓存，重新刷新页面将获取缓存状态
    AddPageState: function (id, controltype, bindloadfun) {
        var self = this;
        self.data.PageStateData.push({ id: id, controltype: controltype });
        if (controltype == "tabbar" && !bindloadfun) {
            $('#' + id).tab({
                defaultIndex: parseInt(self.GetPageStateVal(id) || 0),
                activeClass: 'weui-bar__item_on',
                onToggle: function (index) {
                    self.SetPageStateVal(id, index);
                }
            });
        }
        else if (controltype == "navbar" && !bindloadfun) {
            $('#' + id).tab({
                defaultIndex: parseInt(self.GetPageStateVal(id) || 0),
                activeClass: 'tab-green',
                onToggle: function (index) {
                    self.SetPageStateVal(id, index);
                }
            })
        }
        else if (controltype == "form" && !bindloadfun) {
            var _val = self.GetPageStateVal(id) || "";
            if (_val != "") {
                self.WeUISetForm("#" + id, JSON.parse(_val));
            }

            //每秒钟自动缓存表单数据
            function setformval() {
                var _formval = self.WeUIGetForm("#" + id) || {};
                self.SetPageStateVal(id, JSON.stringify(_formval));
                setTimeout("setformval()", 1000);
            }

            setformval();
        }
        else if (bindloadfun) {
            bindloadfun();
        }
    },
    GetPageStateVal: function (id) {
        return this.GetPageStorage('pagestate_' + id);
    },
    SetPageStateVal: function (id, val) {
        this.SetPageStorage('pagestate_' + id, val);
    },
    //移除页面状态
    // RemovePageState: function (id) {

    // },
    //清除页面所有状态
    // ClearPageState: function () {

    // }
}

//webapp开发
var lobsterlayui = {
    main: function (modname, page, needlogin = true) {
        $(function () {
            lobstercommon.name = "lobsterlayui";
            if (needlogin) {
                lobstercommon.GetWorkId();
                lobstercommon.GetLoginData((right) => {
                    layui.config({
                        base: '/lobsteruiframe/layuiadmin/' //静态资源所在路径
                    }).extend({
                        index: 'lib/index' //主入口模块
                    });

                    layui.define(modname, function () {
                        page.data.$layui = layui;
                        page.pageload(right, layui);
                    });
                }, () => {
                    location.href = "/admin/login/Index.html";
                });
            } else {
                layui.config({
                    base: '/lobsteruiframe/layuiadmin/' //静态资源所在路径
                }).extend({
                    index: 'lib/index' //主入口模块
                });

                layui.define(modname, function () {
                    page.data.$layui = layui;
                    page.pageload(null, layui);
                });
            }
        });
    },
    GetAppId: lobstercommon.GetAppId,
    GetAppKey: lobstercommon.GetAppKey,
    GetSSOToken: lobstercommon.GetSSOToken,
    GetWorkId: lobstercommon.GetWorkId,
    GetSSOUserId: lobstercommon.GetSSOUserId,
    GetSystemConfigs: lobstercommon.GetSystemConfigs,
    SendSMS: lobstercommon.SendSMS,
    GetBaseDict: lobstercommon.GetBaseDict,
    GetAppBaseDict: lobstercommon.GetAppBaseDict,
    GetUrlParam: lobstercommon.GetUrlParam,//获取url中的参数
    GetHeaderData: lobstercommon.GetHeaderData,
    GetLowCodeUrl: lobstercommon.GetLowCodeUrl,
    GET: lobstercommon.GET,
    POST: lobstercommon.POST,
    GETAPI: lobstercommon.GETAPI,
    POSTAPI: lobstercommon.POSTAPI,
    CALLOUTSERVICE: lobstercommon.CALLOUTSERVICE,
    OSSUploadFile: lobstercommon.OSSUploadFile,
    ImportWord: ImportWord,
    //成功登录
    SucceedLogin: function (data) {
        if (data) {
            localStorage.setItem("sso_token", data.sso_token);
            localStorage.setItem("logindata", JSON.stringify(data.logindata));
        }
    },
    //退出登录
    ExitLogin: function () {
        var self = this;
        localStorage.clear();
        location.href = "/admin/login/Index.html";
    },
    //获取用户信息
    GetUserInfo: function () {
        return null;
    },
    //是否移动端
    IsMobile() {
        if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
            return true;
        }
        else {
            return false;
        }
    },
    //json格式判断
    IsJSON: function (str) {
        if (typeof str == 'string') {
            try {
                var obj = JSON.parse(str);
                if (typeof obj == 'object' && obj) {
                    return true;
                } else {
                    return false;
                }

            } catch (e) {
                console.log('error：' + str + '!!!' + e);
                return false;
            }
        }
        console.log('It is not a string!')
    },
}

//amis开发
var lobsteramis = {
    data: {
        $jp: null,
        $amislib: null,
        $amisjson: null
    },
    run: function (jp, amislib, amisjson) {
        this.data.$jp = jp;
        this.data.$amislib = amislib;
        this.data.$amisjson = amisjson;
    },
    main: function (page) {
        lobstercommon.name = "lobsteramis";
        page.data.$jp = this.data.$jp;
        page.data.$amislib = this.data.$amislib;
        page.data.$amisjson = this.data.$amisjson;

        page.pageload();

    },
    GetAppId: lobstercommon.GetAppId,
    GetAppKey: lobstercommon.GetAppKey,
    GetSSOToken: lobstercommon.GetSSOToken,
    GetWorkId: lobstercommon.GetWorkId,
    GetSSOUserId: lobstercommon.GetSSOUserId,
    GetHeaderData: lobstercommon.GetHeaderData,
    GetSystemConfigs: lobstercommon.GetSystemConfigs,
    SendSMS: lobstercommon.SendSMS,
    GetBaseDict: lobstercommon.GetBaseDict,
    GetAppBaseDict: lobstercommon.GetAppBaseDict,
    GetUrlParam: lobstercommon.GetUrlParam,//获取url中的参数
    GET: lobstercommon.GET,
    POST: lobstercommon.POST,
    GETAPI: lobstercommon.GETAPI,
    POSTAPI: lobstercommon.POSTAPI,
    CALLOUTSERVICE: lobstercommon.CALLOUTSERVICE,
}